<?php
	
	if (!class_exists('ctl_order'))
	{
		require_once(CORE_DIR.'/shop/controller/ctl.order.php');
	}
	class collocate_goods_order_ctl extends ctl_order
	{
		function create()
		{
			$this->begin($this->system->mkUrl('cart', 'checkout'));
			$this->_verifyMember(false);
			
			$objCollocOrder = $this->system->loadModel('plugins/collocate_goods/collocOrder');
			$objOrder = &$this->system->loadModel('trading/order');
			$oCart = &$this->system->loadModel('trading/cart');
			$oCart->checkMember($this->member);
			if($_POST['isfastbuy']){
				$cart = $oCart->getCart('all',$_COOKIE['Cart_Fastbuy']);
			}else{
				$cart = $oCart->getCart('all');
			}
			
			
		   if($_POST['delivery']['ship_addr_area']!=''){
				
				$_POST['delivery']['ship_addr'] = str_replace(' ','',$_POST['delivery']['ship_addr_area'].$_POST['delivery']['ship_addr']);
			}
			
			
			
			$orderid = $objCollocOrder->create($cart, $this->member,$_POST['delivery'],$_POST['payment'],$_POST['minfo'],$_POST);
			if($orderid){
				if($_POST['fromCart'] && !$_POST['isfastbuy']){
					$oCart->removeCart();
				}
	/*             $this->redirect('index','order',array($orderid)); */
			}else{
				trigger_error(__('对不起，订单创建过程中发生问题，请重新提交或稍后提交'),E_USER_ERROR);            
			}
			$this->system->setcookie('ST_ShopEx-Order-Buy', md5($this->system->getConf('certificate.token').$orderid));
			$account=$this->system->loadModel('member/account');
			$account->fireEvent('createorder',$this->member,$this->member['member_id']);
			$this->end_only(true, __('订单建立成功'), $this->system->mkUrl('order', 'index', array($orderid)));
			
			$GLOBALS['pageinfo']['order_id'] = $orderid;
			$this->redirect('order','index',array($orderid));
		}
	}

?>